<?php 

$clientId=getClientIdByMail(getSession("login"));

if ($clientId)
{
	
	header("Location: ".createNiceUrl("pageName","client_area"));
	exit;
}

if (getParameter("login") && getParameter("password") && !getParameter("SubmitLogin"))
{
	portalLogin(getParameter("login"),TEAdecrypt(getParameter("password"),KEY));
	
}



?>



<div id="login">


<h1><?php echo $var_shop_login; ?></h1>

    <?php


    if (getParameter("resendactivationlink")){

        $mail=getParameter("resendactivationlink");

       // echo $mail;
        $key=TEAencrypt($mail,KEY);
        $host=$_SERVER['HTTP_HOST'];
        if (isLocal())  $host=getPortalUrl().".betasite.net";
        $link="http://".$host."/?pageName=client_area&key=".$key;


        $data=array();
        $data["link"]=$link;
        $data["portal"]=getPortalName();
        $data["customer"]=getUserFullname();
        sendMailTo($mail, TemplateWithData($var_shop_mail_accountsaved,$data));
        ShowSuccess($var_shop_activation_sent);
    }

    $error=false;

    if (getParameter("SubmitCreate"))

    {


        if (getParameter($portletUID."email_create")==null || ew_CheckEmail(getParameter($portletUID."email_create"))==FALSE) displayError($var_shop_validmailerror,$portletUID."email_create");

        if ($error==false)
        {

            header("Location: ".createUrl("pageName","createaccount","mail",getParameter($portletUID."email_create")));
        }
    }

    if (getParameter("SubmitLogin"))

    {

        if (getParameter($portletUID."email")==null || ew_CheckEmail(getParameter($portletUID."email"))==FALSE) displayError($var_shop_validmailerror,$portletUID."email");
        if (getParameter($portletUID."passwd")==null ) displayError($var_shop_invalidpassword,$portletUID."passwd");

        if ($error==false)
        {
            $mail=getParameter($portletUID."email");
            $password=getParameter($portletUID."passwd");

            $redirect=encryptUrl(createNiceUrl("pageName","client_area"));
            if (getParameter("backurl")) $redirect=getParameter("backurl");
            portalLogin($mail,$password,$redirect);

        }

    }


    ?>

			<?php
					if (getParameter("lostpassword")){
				$error=false;

				$mail=getParameter($portletUID."email");
				if ($mail==null || ew_CheckEmail($mail)==FALSE) displayError($var_shop_validmailerror,$portletUID."email");


                       // echo getClientIdByMail($mail);
                 if (getClientIdByMail($mail)=="") {

                     ShowError($var_shop_accountnotfound);
                     $error=true;
                 }

				if (!$error){




		$host=EW_PORTAL_URL;
		if (isLocal())  $host=getPortalUrl().".betasite.net";
		$link="http://".$host;

                    $data=array();
                    $data["link"]=$link;
                    $data["email"]=$mail;
                    $data["username"]=getUserFullname($mail);
                    $data["password"]=getUserPassword($mail);
                    sendMailTo($mail, TemplateWithData($var_shop_mail_passwordsent,$data));

				ShowSuccess($var_shop_password_sent);
				}
			}
			?>


	<form class="std border rounded" id="create-account_form" method="post" action="<?php echo createNiceUrl("pageName",getParameter("pageName")); ?>">
	<h3><?php echo $var_shop_CreateAccount; ?></h3>
		<fieldset>

			<h4><?php echo $var_shop_createaccount_entermail; ?></h4>
			<p class="text">
				<label for="email_create"><?php echo $var_shop_createaccount_mail; ?></label>
				<span>  <?php formText($portletUID."email_create",0,"account_input"); ?> </span>
			</p>
			<p class="submit">
			<input type="hidden" value="my-account.php" name="back" class="hidden">
                <input type="submit" value="<?php echo $var_shop_CreateAccount; ?>" class="button" name="SubmitCreate" id="SubmitCreate">
				<input type="hidden" value="Créez votre compte" name="SubmitCreate" class="hidden">
			</p>
		</fieldset>
	</form>

	<form class="std border rounded" id="login_form" method="post" action="<?php echo createNiceUrl("pageName",getParameter("pageName")); ?>">
	<h3><?php echo $var_shop_Alreadyin; ?></h3>
		<fieldset>

			<p class="text">
				<label for="email"><?php echo $var_shop_createaccount_mail; ?></label>
				<span><?php formText($portletUID."email",0,"account_input"); ?>  </span>
			</p>
			<p class="text">
				<label for="passwd"><?php echo $var_shop_password; ?></label>
				<span><?php formPassword($portletUID."passwd",0,"account_input"); ?></span>
			</p>
			<p class="submit">
				<input type="hidden" value="my-account.php" name="back" class="hidden">				<input type="submit" value="<?php echo $var_shop_Login; ?>" class="button" name="SubmitLogin" id="SubmitLogin">
				<input type="submit" value="<?php echo $var_shop_passwordforgot; ?>" class="button" name="lostpassword" id="lostpassword">
			</p>
			<!-- <p class="lost_password"><a href="<?php echo  createUrl("action","lostpassword",$portletUID."email",getParameter($portletUID."email"));?>">Mot de passe oublié ?</a>  -->

		</fieldset>

	</form>




						</div>
						
